<script setup>
import { defineEmits } from 'vue';

const props = defineProps({
  cubicles: {
    type: Array,
    required: true
  },
  selectedCubicleId: {
    type: [String, Number],
    default: null
  }
});

const emit = defineEmits(['selectCubicle']);

const selectCubicle = (cubicle) => {
  emit('selectCubicle', cubicle);
};
</script>

<template>
  <van-cell-group inset>
  <div class="cubicle-grid">
    <div
        v-for="cubicle in props.cubicles"
        :key="cubicle.id"
        class="cubicle"
        :class="{ selected: cubicle.id === props.selectedCubicleId }"
        @click="selectCubicle(cubicle)"
    >
      {{ cubicle.name }}
    </div>
  </div>
  </van-cell-group>
</template>

<style scoped>
.cubicle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 8px;
  padding: 12px;
}

.cubicle {
  background: #f0f0f0;
  border-radius: 6px;
  padding: 10px 4px;
  text-align: center;
  font-size: 14px;
  white-space: nowrap;
  font-family: monospace;
  cursor: pointer;
  transition: all 0.3s;
}

.cubicle.selected {
  background-color: #1890ff;
  color: white;
}
</style>
